<meta charset="utf-8">
<div id="cont"></div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
var jsonData = [{'id':'192508'},{'id':'1225'},{'id':'0316'}];
var html = '';
for(var item in jsonData){
html += '<input type="text" name="order_id[]" value="'+jsonData[item].id+'">'+
'<button class="syh">Click</button><p>';
}
$("#cont").html(html);
// console.log(jsonData);
$(document).off().on("click", ".syh", function() {
var index = $(".syh").index(this);
var id=$('input[name="order_id[]"]').eq(index).val();
alert(id);
});
</script>
<meta charset="utf-8">
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Corp</li>
<li>Dell</li>
</ul>
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<div id="cont"></div>
<script type="text/javascript">
var jsonData = [{'id':'192508'},{'id':'1225'},{'id':'0316'}];
var html = '';
for(var item in jsonData){
// html += '<input type="text" class="syh" name="order_id[]" value="'+jsonData[item].id+'"><p>';
html += '<li class="syh" name="order_id[]">'+jsonData[item].id+'</li><p>';
}
$("#cont").html(html);
// console.log(jsonData);
$(document).off().on("click", ".syh", function() {
var index = $(".syh").index(this);
// var id=$('input[name="order_id[]"]').eq(index).val();
var id=$('li[name="order_id[]"]').eq(index).text();
alert(id);
});
</script>
$(document).off().click 在iPhone上需要做如下处理:
<style>
.clickable-div
{
cursor: pointer;
}
</style>
来源:https://stackoverflow.com/questions/3705937/document-click-not-working-correctly-on-iphone-jquery