【问题标题】:How to Pass Knockout ahref value into jquery variable如何将 Knockout ahref 值传递给 jquery 变量
【发布时间】:2017-08-07 16:05:18
【问题描述】:

淘汰js数据

<a data-bind="attr: { href: URLPath }" type="submit">Download</a>

我得到“A 标签”的值为 www.ex.com/sp/file.zip

脚本

function DataItem(data) {
    this.URLPath = ko.observable(data.path); //www.ex.com/sp/file.zip
}

jQuery 脚本

$("input[type=submit]").click(function () {
    $.post('fs.php', 'sp=' + $(this).val(), function (data) {
      -----------
      ----------- 
    });
});

我需要data-bind="attr: { href: URLPath }" (www.ex.com/sp/file.zip) jQuery 变量 "SP="(www.ex.com/sp/file.zip) 中的值这可能吗?

【问题讨论】:

  • 对不起,你的问题我不清楚,你能解释一下你到底想做什么吗?
  • 我需要 data-bind=attr: '{ href: URLPath }' 值到 jquery 变量中
  • 为什么不使用淘汰提交绑定。 knockoutjs.com/documentation/submit-binding.html
  • 嗯,它很有帮助,但如果我得到我建议的答案,它会更有帮助

标签: php jquery knockout.js


【解决方案1】:
function DataItem(data) {
 this.URLPath = ko.observable(data.path); 
}

var mymodel = new DataItem(data);

$(document).ready(function() {
  ko.applyBindings(mymodel);
 $("input[type=submit]").click(function (event) {
    $.post('fs.php', 'sp=' + mymodel.URLPath(), function (data) {
    });
 });
});

【讨论】:

猜你喜欢
  • 2013-06-01
  • 2019-01-17
  • 1970-01-01
  • 2012-02-21
  • 2016-10-13
  • 1970-01-01
  • 2014-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多