jQuery 将文本输入值传递给插件选项

发布于 2024-10-02 17:11:37 字数 823 浏览 1 评论 0原文

我在任何地方都找不到我正在寻找的答案。我有一个生成条形码的插件。你所要做的就是告诉它渲染条形码的元素,它就会把它吐出来。例如:

$("#barcode-target").barcode("Output Goes Here", "code39",{barWidth:2, barHeight:30});
will put a barcode that says "Output Goes Here" into the div #barcode-target. However, I need it to generate a barcode with the value of a certain text input. I tried doing something along the lines of

$(function(){
    $("#barcode").keyup(function () {
      var value = $(this).val();
      $("#barcode-target").text(value);
    }).keyup();
});

当然,这只会在 div 中放入普通字符。我被困住了!

编辑 我也试过了

$(function(){
    var barcodeVal = $("#barcode").val();
    $("#barcode-target").barcode("barcodeVal", "code39",{barWidth:2, barHeight:30});
});

还是不行...

I can't find quite the answer I'm looking for anywhere. I have a plugin that generates barcodes. All you do is tell it what element to render the barcode, and it spits it out. For example:

$("#barcode-target").barcode("Output Goes Here", "code39",{barWidth:2, barHeight:30});

will put a barcode that says "Output Goes Here" into the div #barcode-target.
However, I need it to generate a barcode with the value of a certain text input. I tried doing something along the lines of

$(function(){
    $("#barcode").keyup(function () {
      var value = $(this).val();
      $("#barcode-target").text(value);
    }).keyup();
});

Which, of course, only puts plain characters in the div. I'm stuck!

Edit
I've also tried

$(function(){
    var barcodeVal = $("#barcode").val();
    $("#barcode-target").barcode("barcodeVal", "code39",{barWidth:2, barHeight:30});
});

Still nothing...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年华零落成诗 2024-10-09 17:11:37

您需要按照您所说的方式创建条形码:

$(function(){
  $("#barcode").keyup(function () {
    $("#barcode-target").barcode($(this).val(), "code39", {
      barWidth:2, 
      barHeight:30
    });
  }).keyup();
});

You need to create a barcode the way you said:

$(function(){
  $("#barcode").keyup(function () {
    $("#barcode-target").barcode($(this).val(), "code39", {
      barWidth:2, 
      barHeight:30
    });
  }).keyup();
});
愚人国度 2024-10-09 17:11:37

关于您的编辑,如果您想要传递 barcodeVal 变量的值,则不应将名称放在引号中。

$(function(){
    var barcodeVal = $("#barcode").val();
     // no quotation marks----------v
    $("#barcode-target").barcode( barcodeVal, "code39",{barWidth:2, barHeight:30});
});

否则,您将发送一个字符串文字。

或者您可以放弃该变量,并将 .val() 调用直接放在对 barcode() 的调用中。

$(function(){
     // Get the .val() while calling barcode
    $("#barcode-target").barcode( $("#barcode").val(), "code39",{barWidth:2, barHeight:30});
});

With regard to your edit, if you're wanting to pass the value of the barcodeVal variable, you shouldn't put the name in quotes.

$(function(){
    var barcodeVal = $("#barcode").val();
     // no quotation marks----------v
    $("#barcode-target").barcode( barcodeVal, "code39",{barWidth:2, barHeight:30});
});

Otherwise you were sending a String literal.

Or you could forego the variable, and place the .val() call directly in the call to barcode().

$(function(){
     // Get the .val() while calling barcode
    $("#barcode-target").barcode( $("#barcode").val(), "code39",{barWidth:2, barHeight:30});
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文