记录日常:
最近在使用layer弹窗控件的过程中,发现使用$().val()无法获取input的值。当时和同事试了网上的各种val()取值的方法以及查询了网上的原因,发现网上没有一个合适解决的方法以及合理的解释,真的很苦恼。后来同事发现了一个办法,可以获取值,但是可能造成页面格式的一丢丢的改变,
现在把解决的方法贴出来,各位可以自行试用,当然如果能解决各位的关于layer弹窗获取input值烦恼,也倍感高兴。代码如下:
<script type="text/html" id="Tc" >
<div class="aa">
<div style="width:95%; margin:0px auto 0px auto; padding-left:5px;">
<table width="95%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td colspan="2"><input id ="iphone" type="text" class="input1" name="iphone"
value="请输入手机号码"
onFocus="this.style.color='#333';if (this.value == '请输入手机号码' ) {this.value='';}"
onBlur="this.style.color = '#666';if ( this.value =='' ){this.value = '请输入手机号码';}"/></td>
</tr>
</table>
</div>
</div>
</script>
如上所示:在相应的代码上下添加上
<script type="text/html">
内容
</script>
就可以通过$().val()获取想要的input的值了。。。