如何在PHP中使用JavaScript更改下拉列表的文本 [英] How to change the text of the drop down list using JavaScript in PHP

查看:93
本文介绍了如何在PHP中使用JavaScript更改下拉列表的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的代码有问题,我想在选择并单击按钮后更改下拉列表的文本,我想在单击按钮后选择下拉列表的默认文本,即选择" ,
例如,单击按钮后,我在列表中选择"PCS",列表应将其文本更改为选择".
我对此过程存有疑问,不知道该怎么办,请帮我一下,这是我的示例代码.非常感谢.

Hello guys,

Im having a problem in my code, i want to change the text of my drop-down list after i select and click a button, i want to select the default text of my drop-down list which is "Select" after clicking a button,
For example i choose "PCS" in my list after i click the button the list should change its text to Select.
I''ve been stock on this process and don''t know what do, can you please give me a hand, here''s my sample code. Thank you very much.

<script>
function Request()
{

var list= document.getElementsByName(''unit'')[0].text= ''Select'';

}
</script>

	
$listof_products .=''<select id="unit" name="unit" style="margin-left: 10px;">
        <option value="" selected="selected">Select</option>
	
	<option value="PCS">PCS</option>
       
        <option value="RMS">RMS</option>
	
	
	<option value="PKG">PKG</option>
	
		
        $listof_products .=''</select>'';



  <button name="addtocart" title="Request Quotation Price" class="redButton" type="submit"  önclick="Request()"><span><span>Request Quote</span></span></button>

推荐答案

listof_products.=''< select id ="unit" name ="unit" style ="margin-left:10px;"> < option value =" selected ="selected"> Select</option> < option value ="PCS"> PCS</option> < option value ="RMS"> RMS</option> < option value ="PKG"> PKG</option>
listof_products .=''<select id="unit" name="unit" style="margin-left: 10px;"> <option value="" selected="selected">Select</option> <option value="PCS">PCS</option> <option value="RMS">RMS</option> <option value="PKG">PKG</option>


listof_products.=''</select>''; < button name ="addtocart" title =请求报价价格" class ="redButton" type ="submit"önclick="Request()"< span>< span>请求报价</span>< /span></button>
listof_products .=''</select>''; <button name="addtocart" title="Request Quotation Price" class="redButton" type="submit" önclick="Request()"><span><span>Request Quote</span></span></button>


尝试使用此Javascript函数

Try using this Javascript function

<script>
function Request()
{
   document.getElementById('unit').value= 'Select';
}
</script>


这篇关于如何在PHP中使用JavaScript更改下拉列表的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆