Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态更改锚链中的值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 动态更改锚链中的值

Javascript 动态更改锚链中的值,javascript,jquery,html,Javascript,Jquery,Html,我期待着动态地改变价格和id值,并在下面的锚链接中选择不同的下拉列表。比如,如果我选择3天,锚定中的价格将更改为24,id为新oID 注意:隐藏字段用于在数据库中提交数据$\u发布['deadline']。是的,正在更正url。类型错误 <a class="btn btn-warning" href="https://example.com?price=38&id=DS123">order</a> 您可以在锚点中放置id,如: 然后在onchange函数(f

我期待着动态地改变价格和id值,并在下面的锚链接中选择不同的下拉列表。比如,如果我选择3天,锚定中的价格将更改为24,id为新oID

注意:隐藏字段用于在数据库中提交数据<代码>$\u发布['deadline']。是的,正在更正url。类型错误

<a class="btn btn-warning" href="https://example.com?price=38&id=DS123">order</a>

您可以在锚点中放置id,如:

然后在onchange函数(
func
)中执行以下操作:

$('#btn order').attr('href','https://example.com?price=“+option+”&id=“+oID);

您在HTML中有不必要的隐藏字段,在jQuery中也有不必要的
if
条件(因为我无法在您的场景中看到并充分利用这些条件)

按如下方式操作:-

函数func(){
var期权=$(“#价格”).val();
var mID=new Date().getTime();
变量oID='Q'+数学四舍五入(mID/1000)
$('.btn warning').attr('href',”https://example.com?price=“+选项+”&id=“+oID”)
};

紧急情况*:
选择紧急状态
三天
5天
7天

您可以尝试使用jquery.on()来保持它的整洁,而不是使用onchange=func():

香草js版本:

function func () {
   var e = document.getElementById("price");
   var price = e.options[e.selectedIndex].value;
   var button = document.getElementsByClassName('btn btn-warning')[0];

   if (price && button) {
      var mID = new Date().getTime();
      var oID = 'Q'+Math.round(mID/1000);
      button.setAttribute('href', "https://example.com?price=" + price + "&id=" + oID)
   }
}

那么如何处理隐藏字段呢?我想你忘了包括?com应该改为
function func() {
var option = $("#price").val();
var dLine = $('#deadline').val();
var mID = new Date().getTime();
var oID = 'Q'+Math.round(mID/1000)

if (option =='24') {
  dLine = 3 Days;
  oID;
}

if (option =='38') {
  dLine = 5 Days;
  oID;
}

if (option =='62') {
  dLine = 7 Days;
  oID;     
  }
};
    $('#price').on('change', function(e){
         var $thisSelect = $(this),
             $anchor = $('.btn.btn-warning'),
             oID = 'Q'+Math.round((new Date().getTime())/1000),
             newhref = 'https://example.com/?id='+oID+'&price='+$thisSelect.val(),
             selectedText = $thisSelect.find('option:selected').text();

         $anchor.prop('href', newhref);

         $('#deadline').val(selectedText);
         $('#oid').val(oID);
   });
function func () {
   var e = document.getElementById("price");
   var price = e.options[e.selectedIndex].value;
   var button = document.getElementsByClassName('btn btn-warning')[0];

   if (price && button) {
      var mID = new Date().getTime();
      var oID = 'Q'+Math.round(mID/1000);
      button.setAttribute('href', "https://example.com?price=" + price + "&id=" + oID)
   }
}