怎么在js中对获取input中自定义的熟悉

在js中怎么修改<input type="text" id ="trainnumber" name="myText" selectBoxOptions=";;;"/>中的selectBoxOptions属性的内容

第1个回答  2013-07-21
jquery中arrt()既可以取值也可以修改属性的值:测试代码
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#Btn1").click(function(){
alert(($("#trainnumber").attr("selectBoxOptions")));
$("#trainnumber").attr({"selectBoxOptions" : "test111" });
alert(($("#trainnumber").attr("selectBoxOptions")));
});
});
</script>
</head>
<body>
<button id="Btn1" name="Btn1">点击</button>
<input type="text" id ="trainnumber" name="myText" selectBoxOptions=";;;"/>
</body>
</html>
当然,用document.getElementById()也可以。
希望能帮到你 谢谢本回答被提问者和网友采纳
第2个回答  2013-07-21
在标签里可以随意加入自定义的属性,然后赋值就可以了。js中可以直接使用.读取。但是这个在firefox里不被支持,应该通过更好的办法实现结果。
上面的程序可以直接document.getelementbyid('tainnumber').selectBoxOptions访问就行了。
第3个回答  2015-09-03

通过attributes方式获取自定义属性。

示例:

<body>
<input id='ipt' selfvalue='1'/>  设置自定义属性selfvalue
</body>
<script>
  var a=document.getElementById('ipt').attributes.selfvalue.value;//获取自定义属selfvalue的值
</script>

第4个回答  2013-07-21
$("#trainnumber").attr('selectBoxOptions',‘xxxx’);
自定义属性的话又兼容性问题
第5个回答  2013-07-21
document.getElementById("trainnumber").selectBoxOptions
相似回答
大家正在搜