获取selected的值
html
<select class="contents_input_option" onchange="gradeChange()" id="pid" name="verify_id" placeholder="请选择一项"> <option value="-1">请选择签署人</option> {foreach $userInfo as $key=>$v} <option value="{$key}" data-name="{$v.name}" data-phone="{$v.phone}" data-account_type="{$v.account_type}">{$v.name} </option> {/foreach} </select>
js
function gradeChange(){ var op = document.getElementById("pid"); console.log(op.options[op.selectedIndex].value); }
获取data-name的值
function gradeChange(){ var op = document.getElementById("pid"); console.log(op.options[op.selectedIndex].getAttribute("data-name")); console.log(op.options[op.selectedIndex].dataset.name); }
jq的方法
var id = $("#pid").data("name"); var id = $("#pid").attr("data-name");