
$('#selectForm').click(function(e) { e.preventDefault(); var action = $(this).data('ID'); var type = $(this).data('name'); console.log(action+' '+type); }); @H_403_7@// jquery的 @H_403_7@ <form ID="selecttest"> <label for="fruit">Please select at least two fruits</label><br> <select ID="fruit" name="fruit" size="5"> <option data-ID="1" data-name="norman">Banana</option> <option data-ID="2" data-name="james">Apple</option> <option data-ID="3" data-name="lars">Peach</option> <option data-ID="4" data-name="john">Turtle</option> </select> <input type="submit" ID="selectForm" value="ValIDate Selecttests"> </form>解决方法 这是演示 – http://jsfiddle.net/tnVfV/ @H_403_7@ @H_403_7@这是代码: @H_403_7@
$('#selectForm').click(function (e) { e.preventDefault(); var action = $('#fruit option:selected').attr('data-ID'); var type = $('#fruit option:selected').attr('data-name'); console.log(action + ' ' + type);}); @H_403_7@data-ID和data-name是选项的属性.您可以使用本机属性ID和名称… @H_403_7@好的,因为tymeJV评论这里是使用data()的代码: @H_403_7@ $('#selectForm').click(function (e) { e.preventDefault(); var action = $('#fruit option:selected').data('ID'); var type = $('#fruit option:selected').data('name'); console.log(action + ' ' + type);}); @H_403_7@演示http://jsfiddle.net/tnVfV/1/ 总结 以上是内存溢出为你收集整理的从表单的select选项的值中获取jquery数据属性全部内容,希望文章能够帮你解决从表单的select选项的值中获取jquery数据属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)