【问题标题】:Converting code from PrototypeJS to jQuery将代码从 PrototypeJS 转换为 jQuery
【发布时间】:2014-05-12 05:31:16
【问题描述】:

在将 PrototypeJS 转换为 jQuery 时遇到问题。我的原型 JS 是

function remove_invitation(target) {
  if (confirm('Delete this invitation?')) {
    $$('div#'+target+' input.hidden_delete')[0].setValue('1')
    Element.hide(target);  
   }
}

我已经转换成jQuery了

function remove_chore(target) {
  if (confirm('Delete this chore?')) {
    $('div#'+target+'input.hidden_delete').first().val(1);
    // $('div#'+target).hide();
    $('div#'+target).css("display","none");
  }
}

但它无法正常工作,因为它正在工作 PrototypeJS。

【问题讨论】:

  • 它们都是 JavaScript。看起来您正在尝试将最初使用 PrototypeJS 库编写的代码转换为使用 jQuery。但这不会改变您使用的语言
  • $('#'+target).hide().find("input.hidden_delete:first").val(1);
  • @epascarello 谢谢。它有效。
  • @AmritdeepDhungana 我的回答对你有用吗?

标签: javascript jquery prototypejs prototype


【解决方案1】:

尽量在这里留个空格:

$('div#'+target+' input.hidden_delete').first().val(1);
// --            ^ add space here

另外,由于id 是独一无二的,您可以使用# 代替div#

function remove_chore(target) {
    if (confirm('Delete this chore?')) {
        $('#'+target+' input.hidden_delete').first().val(1);
        // $('div#'+target).hide();
        $('#'+target).css("display","none");
    }
}

【讨论】:

    猜你喜欢
    • 2012-03-08
    • 2017-09-23
    • 2016-04-09
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    相关资源
    最近更新 更多