
学习javascript的时候在input 里自己添加的属性值怎么调用不出来
<html><head><metahttp-equiv="content-type"content="text/html;charset=utf-8"/></head><...
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<h1>请选择你喜欢的水果</h1>
<input type="checkbox" onclick="shop(this,10)" name="fruits" value="苹果" price="10">苹果<br/>
<script language="javascript" type="text/javascript">
function shop(obj,price){
var fruits=document.getElementsByName("fruits");
window.alert(fruits[0].price);
}
</script>
</body>
</html>
在标签<input>中自己添加了属性price="10"怎么调用不出来? 展开
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<h1>请选择你喜欢的水果</h1>
<input type="checkbox" onclick="shop(this,10)" name="fruits" value="苹果" price="10">苹果<br/>
<script language="javascript" type="text/javascript">
function shop(obj,price){
var fruits=document.getElementsByName("fruits");
window.alert(fruits[0].price);
}
</script>
</body>
</html>
在标签<input>中自己添加了属性price="10"怎么调用不出来? 展开
展开全部
var vprice=document.getElementsByName("fruits")[0].getAttribute('price');
alert(vprice);
alert(vprice);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询