我有一个 html 形式的输入,我需要将它们发送到脚本。它有 name 和 id 。
<p>
<select onchange="myFunction(this.value)" name="shippcity" id="shippcity">
<option value="0">state</option>
</select>
<input type="hidden" name="calc_shipping_city" id="shipping_city" value="" />// will be removed
</p>
<script>
function myFunction(val) {
if ( val === '' ) {
}
else {
//input val to name="calc_shipping_city" and id="shipping_city"
document.getElementById("shipping_city").value = val;
}
}
</script>
woocomerce 也有此代码:
<?php
}
$my_city = $woocommerce->customer->get_shipping_city();
$my_city = explode('-', $my_city);
if(isset($my_city) && intval($my_city[0]) > 0 ){
?>
set_initial_val('shipp', 'city', <?php echo $my_city[0]; ?>);
最佳答案
每个输入元素都有一个可以设置的 value
属性。
function myFunction(val) {
if ( val === '' ) {
}
else {
document.getElementById("shipping_city").value = val;
document.getElementById("shippcity").form.submit();
}
}
关于javascript - 如何在javascript中输入名称和id的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651693/