【问题标题】:passing element id by javascript function to xajax php function通过javascript函数将元素ID传递给xajax php函数
【发布时间】:2012-12-02 10:42:09
【问题描述】:

我正在使用 xajax 函数检查用户名的可用性,我希望它在 anchar 标记上单击。我这样做就像onclick="xajax_checkusername('getElementByid(\"username\").value')。但它不工作。租赁帮助

【问题讨论】:

  • onclick="xajax_checkusername('getElementByid(\"username\").value')" 我在按钮上调用它说。 checkusername($username) 是 php 函数

标签: php javascript xajax


【解决方案1】:

你错误地传递了参数,去掉单引号让它变成

onclick="xajax_checkusername(document.getElementByid('username').value)"

请注意,不建议使用这种内联 Javascript,因为它会成为维护的噩梦

【讨论】:

  • 它还有其他方法可以通过这个
  • 'not working' 信息不足,您是否在控制台中看到任何错误? F12
  • 用户名:    检查可用性这些是表单元素
  • 请用代码更新您的问题,cmets 不适用于整个代码块
【解决方案2】:

请使用;

onclick="xajax_checkusername(xajax.$('username').value);"

用户名字段ID标签值必须是“用户名” 例如

【讨论】:

    【解决方案3】:

    在你的例子中

    getElementByid(\"username\").value
    

    应该是

    document.getElementById("username").value // id should be ID
    

    【讨论】:

    • onclick="xajax_checkUsername('document.getElementById(\'username\').value')" 这也不起作用
    • \'username\' 应该是'username'
    【解决方案4】:

    试试这个

    onclick=\"xajax_checkusername(getElementById('username').value))\";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2017-04-14
      • 1970-01-01
      • 2011-07-15
      • 2020-11-24
      • 1970-01-01
      相关资源
      最近更新 更多