我正在尝试使用onchange获取选择框的值,但是当我使用this.val
时
<select name="type" name="auctionlength" onchange="listing_type();" id="listingtype" class="form-control">
<option><?php echo System::translate("Choose an option"); ?></option>
<option value="auction"><?php echo System::translate("Auction"); ?></option>
<option value="buy"><?php echo System::translate("Buy It Now"); ?></option>
</select>
以下是我的功能:
var listing_type = function()
{
console.log(this.val);
}
我尝试了以下方法:
this.val();
this.value()
this.value
$(this).val()
$(this).value()
但还是不行?
答案 0 :(得分:0)
像这样:
HTML
<select name="type" name="auctionlength" onchange="listing_type(this.value);" id="listingtype" class="form-control">
<option><?php echo System::translate("Choose an option"); ?></option>
<option value="auction"><?php echo System::translate("Auction"); ?></option>
<option value="buy"><?php echo System::translate("Buy It Now"); ?></option>
</select>
JS
function listing_type(value){
console.log(value);
}