【问题标题】:Create Form w/ javascript and pass variable to function使用 javascript 创建表单并将变量传递给函数
【发布时间】:2013-03-19 06:08:03
【问题描述】:

我可以用 javascript 创建一个文本框,然后单击,传递一个带参数的函数吗?注释掉的行下面是问题

var inputBox = document.createElement("input");

inputBox.staff = project.staff[j].name;
inputBox.defaultValue = inputBox.staff;
inputBox.onchange = changeHours;

//inputBox.onclick = selectText(this);

【问题讨论】:

    标签: javascript forms function textbox


    【解决方案1】:
    inputBox.onclick=function(argument){
      selectText(this);
    };
    

    【讨论】:

      【解决方案2】:

      试试

      inputBox.onclick=function(){selectText(this)};
      

      http://www.w3schools.com/jsref/event_onclick.asp

      【讨论】:

        【解决方案3】:

        只需将onclick 设置为您想要的功能即可。

        var inputBox = document.createElement("input");
        
        inputBox.staff = project.staff[j].name;
        inputBox.defaultValue = inputBox.staff;
        inputBox.onchange = changeHours;
        inputBox.onclick = function() {
            selectText(this);
        };
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-08-21
          • 2015-05-02
          • 1970-01-01
          • 2014-01-04
          • 2017-04-30
          • 2018-12-14
          • 2014-10-31
          相关资源
          最近更新 更多