javascript - 如何在javascript中输入名称和id的值?

标签 javascript html

我有一个 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/

相关文章:

javascript - 表单的 reset() 方法不会重置具有 value 属性的输入

javascript - 如何正确设置Interval Generator?

javascript - 在 Select2 中设置文本值

javascript - ElevateZoom,在始终打开的不同 div 上显示缩放部分

html - 链接标签中的颜色不起作用,但链接标签中的 div 颜色有效?

html - 100vh 在手机上不够高

javascript - 停止 ng-repeat 然后恢复它

javascript - 使用 ajax 函数在 codeigniter 中重定向

javascript - 从 GWT 代码调用 getElementsByTagNameNS

html - 分层 css - 如何限制第二层的背景