JavaScript功能不会自动添加具有价格的文本框

javascript fucntions are not automatically filiing textboxs having prices

本文关键字:文本 添加 功能 JavaScript      更新时间:2023-09-26
 if (document.getElementById("event-type").innerHTML === "Fashionshoot") 
    {  document.getElementById("act_price").innerHTML="50000";      document.getElementById("adv_price").innerHTML=cal(document.getElementById("act_price").innerHTML);          
    } } 
function cal(actual)
 {  advance=(actual)*20/100;
    return advance; }

而 HTML 代码是

<TD VALIGn="TOP"><select name="event_type" class="textfield" id="event-type" onChange="price()">

在选择元素中,您不会获得带有 innerHTML 的选定文本。您必须使用selectedIndex获取所选值我修复了你的功能。您可以使用此脚本:

function price()
{
    var selectInput= document.getElementById("event-type");
    if (selectInput.options[selectInput.selectedIndex].text === "Fashionshoot") 
    { 
        document.getElementById("act_price").innerHTML="50000";
        document.getElementById("adv_price").innerHTML=cal(document.getElementById("act_price").innerHTML);          
    }
}