【发布时间】:2014-04-22 19:56:58
【问题描述】:
在这段代码中,JQuery 代码在 Firefox 和 Chrome 上运行时无法在 Internet Explorer 中运行//alert($('input[type="text"]').eq(0).val());
为什么这里没有显示此提醒?
<html>
<head>
<style>
div {
border: 2px solid blue;
}
.a {
color: red
}
.b {
background-color: green;
}
.c {
font-size: 55px;
}
</style>
</head>
<body>
<div id="container">this is my div
<input type="text" value="50" name="first_input">first label</input>
<button>first button</button>
<input type="text">second label</input>
<input type="text">third label</input>
<input type="text">fourth label</input>
<button>second button</button>
<input type="text">fifth label</input>
<button>third button</button>
<input type="text">sixth label</input>
<button>fourth button</button>
<input type="text">seventh label</input>
<button>fifth button</button>
<button>sixth button</button>
<button id="ss">seventh button</button>
<label id="lbl1">hello</label>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('input:text').eq(0).attr({
title: 'please input the value',
placeholder: 'insert a value',
name: 'input_type',
//value:25
});
$('#ss').click(function () {
<!-- alert($('input[type="text"]').get(0).value); this is not work on I.Explorer -->
<!-- alert($('input[type="text"]').get(0).name); this is not work on I.Explorer -->
<!-- alert($('input[type="text"]').eq(0).val()); -->
alert($('input[type="text"]').eq(0).val()); <!-- this is not work on I.Explorer -->
});
});
</script>
</body>
</html>
【问题讨论】:
-
name:'input_type', -
请到jsfiddle.net 做个小技巧,发到这里,我们可以帮助你:)
-
@DanielCheung 上面有足够的代码不需要 jsfiddle。人们太快要求这个了。
-
@SalmanA 一针见血。在大多数浏览器中,您可以在对象构造函数中使用尾随逗号,但 IE 则不行。它倒下,之后停止所有代码执行。
-
解决方案 HERE 说 使用短结束标签,这意味着使用
<input>..</input>而不是<input .../>