我有一个表格和jquery,用于按类
获取值this
function sendModel(el){
var id_model = $(el).class('id_model');
alert(id_model);
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input name='id_model' class='id_model' value='M001'>
<button onclick='sendModel(this)'> send </button>
</form>
&#13;
如何用id_model
值显示警告?谢谢你们
答案 0 :(得分:1)
$('#myForm').submit(function(e){
e.preventDefault();
var id_model = $('.id_model').val();
alert(id_model);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm">
<input name='id_model' class='id_model' value='M001'>
<button type="submit"> send </button>
</form>
function sendModel(){
var id_model = $('.id_model').val();
alert(id_model);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input name='id_model' class='id_model' value='M001'>
<button onclick='sendModel()'> send </button>
</form>
答案 1 :(得分:0)
你可以尝试一下吗?
var id_model = $('.id_model');
alert(id_model.attr('value'))