button的value

本文探讨了使用jQuery在Internet Explorer中从button元素获取value属性的问题。在IE中,$(#mybtn).val()返回的是按钮的文本内容而非value属性值,而在Firefox中则正常。文中提供了解决方案,包括使用$(#mybtn).attr(value)及改用input标签。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天又碰到了SB问题,其实我只想得到button的value,因为我的控件用的是button标签,悲剧呀。代码如下

<button  value="css btn" id="mybtn">Text</button>

 而我用jquery来获取这个button的值,我发现 IE 获得的其实是Text,并不是里面的value 属性,而火狐是正常的。

$(document).ready(function(){
		//var v=$("#mybtn").val();
		var v=$("#mybtn").attr("value");
		alert(v);   
						   });

 




(IE)

(FF)

怎么办呢?最后测试了,能用两种方法:

(1):就不要用value属性了,加一个其他属性,如data,(这样好像不是很好,因为button并没有data属性)

(2):该用<input type="button" ,看来这样比较好些哦

 

 

 

 

 

 

代码解释: <body BGCOLOR=gray onload="jsInitialByDeviceType()"> <left> <Table border = 0 cellspacing = 0 cellpadding = 0> <tr> <td> <div id="EXAMPLE_DIV_ID"> </div> <script type="text/javascript"></script></td> </tr> <tr> <td align=center> <INPUT type = button VALUE = "保存圖片" id = 'SaveDraingImage' disabled = "disabled" ONCLICK = 'jsSaveToImageFilePath("myObject")' />   <INPUT type = button VALUE = "清除" id = 'Clear' ONCLICK = 'jsClear("myObject")' disabled = "disabled" /></td> </tr> </Table> <form> <Table class="MsoTableGrid tab2" border=1 cellspacing=0 cellpadding=0 style="display: none" > <tr> <td> Device Type: </td> <td> <textarea id = "devicename" cols = "20" rows = "1" style="font-size: 14px; overflow:hidden; background-color:#FEFF91; border:0;" readonly="readonly"></textarea> </td> <td><input type="button" VALUE = "Select Device" id = "change" name="change" onclick='jsBackToSelectDevice("myObject")'></td> <!-- <td><INPUT type = button VALUE = "Uninitial" id = 'Uninitial' ONCLICK = 'jsUnInitialDevice("myObject")' disabled = "disabled" /></td> --> <td><INPUT type = button VALUE = "About" id = 'About' ONCLICK = 'jsAboutBox("myObject")' disabled = "disabled" /></td> <td> </td> <td><INPUT type = button VALUE = "Set Background" id = 'SetBK' ONCLICK = 'jsSetBackgroundImage("myObject")' disabled = "disabled" /></td> </tr> <tr> <td> Pen Color: </td> <td> <select name="pencolor" id = 'pencolor' disabled = "disabled" onchange = 'jsSetPenColor("myObject")' > <option value = "1">Red</option> <option value = "2">Green</option> <option value = "3">Blue</option> <option value = "4">Black</option> <option value = "5">White</option> </select> </td> <td> Pen Width:</td> <td> <select name = "penwidth" id = 'penwidth' onchange = 'jsSetPenWidth("myObject")' > </select> </td> <td> Pen Style:</td> <td> <select name = "penstyle" id = 'penstyle' disabled = "disabled" onchange = 'jsSetPenStyle("myObject")'> </select> </td> </tr> <tr> <td> </td> <td> <select name = "savetype" id = 'savetype' disabled = "disabled" > <option value = "1" selected="true">JPG</option> <option value = "2">BMP</option> <option value = "3">PNG</option> <option value = "4">GIF</option> <option value = "5">TIFF</option> </select> </td> <td> <select name = "savedpi" id = 'savedpi' disabled = "disabled" > <option value = "0" >150 dpi</option> <option value = "1">300 dpi</option> </select> </td> <td><INPUT type = button VALUE = "Get Size" id = 'getsize' disabled = "disabled" ONCLICK = 'jsGetPointSize("myObject")' /></td> <td> <select id="points"> </select> </td> <td><INPUT id="pointInfo" type="button" VALUE="ShowPointInfo" ONCLICK="jsGetPointData('myObject')"/></td> </tr> <tr> <td><INPUT type = button VALUE = "Save Drawing Video" id = 'SaveDraingVideo' disabled = "disabled" ONCLICK = 'jsSaveToVideoFilePath("myObject")' /></td> <td> <select name = "saveformat" id = 'saveformat' disabled = "disabled" > <option value = "1">MP4</option> <option value = "2">WMV</option> </select> </td> <td> <select name = "savefps" id = 'savefps' disabled = "disabled" > <option value = "1">5 FPS</option> <option value = "2">10 FPS</option> <option value = "3">15 FPS</option> <option value = "4">20 FPS</option> <option value = "5">25 FPS</option> <option value = "6" selected>30 FPS</option> <option value = "7">60 FPS</option> <option value = "8">90 FPS</option> <option value = "9">120 FPS</option> <option value = "10">150 FPS</option> </select> </td> <td></td> <td></td> <td></td> </tr> <tr> <td><INPUT type = button VALUE = "ActiveTablet" id = 'enabletablet' disabled = "disabled" ONCLICK = 'jsActiveTablet("myObject", 1)' /></td> <td><INPUT type = button VALUE = "DeactiveTablet" id = 'disenabletablet' disabled = "disabled" ONCLICK = 'jsActiveTablet("myObject", 0)' /></td> <td><o:p> </o:p></td> <td><o:p> </o:p></td> <td><o:p> </o:p></td> <td><INPUT type = button VALUE = "Get Valid" id = 'getvalid' disabled = "disabled" ONCLICK = 'jsGetProtectValidStatus("myObject")' /></td> </tr> <tr> <td><INPUT type = button VALUE = "Pad ID" id = 'padid' disabled = "disabled" ONCLICK = 'jsGetPadID("myObject")' /></td> <td><INPUT type = button VALUE = "Pen ID" id = 'penid' disabled = "disabled" ONCLICK = 'jsGetPenID("myObject")' /></td> <td><INPUT type = button VALUE = "Version ID" id = 'versionid' disabled = "disabled" ONCLICK = 'jsGetVersionID("myObject")' /></td> <td><INPUT type = button VALUE = "Display Version ID" id = 'displayversionid' disabled = "disabled" ONCLICK = 'jsDisplayVersionID("myObject", 1)' /></td> <td><INPUT type = button VALUE = "Hide Version ID" id = 'hideversionid' disabled = "disabled" ONCLICK = 'jsDisplayVersionID("myObject", 0)' /></td> <td><o:p> </o:p></td> </tr> <tr> <td><INPUT type = button VALUE = "Close LED" id = 'closeled' disabled = "disabled" ONCLICK = 'jsCloseLed("myObject")' /></td> <td><INPUT type = button VALUE = "Open LED" id = 'openled' disabled = "disabled" ONCLICK = 'jsOpenLed("myObject")' /></td> <td><INPUT style="display:none" type = button VALUE = "Save Device Image" id = 'SaveDeviceImage' disabled = "disabled" ONCLICK = 'jsSaveDeviceIamge("myObject")' /></td> <td> <input type="text" id="HorMargin" name="" value="" placeholder="Width"> </td> <td> <input type="text" id="VerMargin" name="" value="" placeholder="Height"> </td> <td><INPUT type = button VALUE = "Set Clip" id="SetCenterImageClip" disabled = "disabled" ONCLICK = 'jsSetCenterImageClip("myObject")' /></td> </tr> <tr> <td><INPUT type = button VALUE = "Upload Data Into Device" id = 'SaveDeviceData' disabled = "disabled" ONCLICK = 'jsSaveDeviceData("myObject")' /></td> <td> <select name = "writefile" id = 'writefile' disabled = "disabled" > <option value = "1">1</option> <option value = "2">2</option> <option value = "3">3</option> <option value = "4">4</option> <option value = "5">5</option> </select> </td> <td><INPUT type = button VALUE = "Download Device Data" id = 'ReadDeviceData' disabled = "disabled" ONCLICK = 'jsReadDeviceData("myObject")' /></td> <td> <select name = "readfile" id = 'readfile' disabled = "disabled" > <option value = "1">1</option> <option value = "2">2</option> <option value = "3">3</option> <option value = "4">4</option> <option value = "5">5</option> </select> </td> <td><INPUT type = button VALUE = "Clear Device Data" id = 'ClearDeviceData' disabled = "disabled" ONCLICK = 'jsClearDeviceData("myObject")' /></td> <td> <select name = "deletefile" id = 'deletefileselect' disabled = "disabled" > <option value = "0">0</option> <option value = "1">1</option> <option value = "2">2</option> <option value = "3">3</option> <option value = "4">4</option> <option value = "5">5</option> </select> </td> </tr> </Table> <P> <Table border = "1" style="display: none"> <tr> <td><b>Image encoding using the Base64</b></td> </tr> <tr> <td id="encodeType"> <input type = "button" id = "encode1" value = "Bmp" disabled = "disabled" ONCLICK = 'jsPacketsBase64Encode(1)'> <input type = "button" id = "encode2" value = "Jpg" disabled = "disabled" ONCLICK = 'jsPacketsBase64Encode(2)'> <input type = "button" id = "encode3" value = "Png" disabled = "disabled" ONCLICK = 'jsPacketsBase64Encode(3)'> <input type = "button" id = "encode4" value = "Gif" disabled = "disabled" ONCLICK = 'jsPacketsBase64Encode(4)'> <input type = "button" id = "encode5" value = "Tiff" disabled = "disabled" ONCLICK = 'jsPacketsBase64Encode(5)'> <input type = "button" id = "encode6" value = "Ink" disabled = "disabled" ONCLICK = 'jsPacketsBase64Encode(6)'> </td> </tr> </table> <Table border = "1" style="display: none"> <tr> <td><textarea id = "theTextEncode" cols = "125" rows = "10"></textarea></td> </tr> <tr> <td><INPUT TYPE = button VALUE = "Base64 Decode" id = 'decode' disabled = "disabled" ONCLICK = 'jsBase64Decode("myObject")' /></td> </tr> <tr> <td><textarea id = "theTextInkData" cols = "125" rows = "10"></textarea></td> </tr> </table> <!-- <input type="hidden" runat="server" id="devicename" name="devicename"> --> </form> </center> </body>
最新发布
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值