Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.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 将jquery输出获取为html输出_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 将jquery输出获取为html输出

Javascript 将jquery输出获取为html输出,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我正在将一些值从html传递给javascript方法,我想将内容传递给html元素 $('#qtyorder span').each(function(){ var id =($(this).prop('id')); var thenum = id.replace(/^\D+/g, ''); var qty=$("#qty_ordered_"+thenum).html(); if($("#qty_rec"+thenu

我正在将一些值从html传递给javascript方法,我想将内容传递给html元素

$('#qtyorder span').each(function(){
         var id =($(this).prop('id'));
         var thenum = id.replace(/^\D+/g, ''); 
         var qty=$("#qty_ordered_"+thenum).html();

          if($("#qty_rec"+thenum).val() == ''){                
                $("#qty_rec"+thenum).val(qty);
                jQuery('#ordDate'+thenum).val($.datepicker.formatDate('d/mm/yy', new Date()));
                $("#ordDate"+thenum).trigger('click');

                 }
我的html表单是这样的,我想通过使用id传递值

<form
    class="overlay_form width_control_473 receive_autofil_popup padding_control_bottom_20"
        <input type="hidden" id="qty_rec" value="" /> <input type="hidden"
            id="qty_rec" value="" /> <input type="hidden" id="dateRcvd"
            value="" /> <input type="hidden" id="p_on" value="" /> <label
            class=" label_break_b verd12dgray">Item Code</label>
        <div class="clear_fix"></div>
        <input
            class="input_md_rd radious_all innershadow padding_control width_control_168"
            name="" type="text" id="code">
    </div>

    <div class="pur_field_container float_left">
        <label class=" label_break_b verd12dgray">Quantity Ordered</label>
        <div class="clear_fix"></div>
        <input
            class="input_md radious_all innershadow padding_control width_control_168"
            name="" type="text" id="qty_rec">
    </div>
    <div class="pur_field_container ">
        <label class=" label_break_b verd12dgray">Quantity Received</label>
        <div class="clear_fix"></div>
        <input
            class="input_md radious_all innershadow padding_control width_control_168"
            name="" type="text" id="qty_rec"
            onkeyup="cancelOrderAutofilNotification()">
            <input
            class="input_md radious_all innershadow padding_control width_control_168"
            name="" type="text" id="qty_rec"
            onkeyup="confirmOrderAutofilNotification()">
    </div>
    <div
        class="field_container_b width_control_317 margin_control_top float_left">
         <input
            type="button" value="Cancel"
            class="close button_gray_md1 radious_all verd12dgray float_left margin_control_top_10 "
            name="">
    <input  type="button" value="Confirm"
            class="confirm button_gray_md1 radious_all verd12dgray float_left margin_control_top_10 "
            name="" onclick="confirmOrderAutofilNotification();">

    </div>
</form>

如何将javascript值传递到此表单?

假设您希望使用javascript的输出更新div

 <div id = "content"></div>
因为您已经在使用jQuery,所以可以使用

$('#content').html("Your HTML here");

在javascript中,我们有两个方法将值设置为elements.val和.html。您可以将.val用于文本输入或选择输入等输入元素。html用于span、div、p、labels等元素,在本例中,您应该使用from.html。

以下是使用jquery更改html和输入值的实时示例

使用$'element.val更改输入值,使用$'element.html更改html内容

$document.readyfunction{ $“更改”。单击函数{ $'myInput'.val'XYZ';///element.val用于输入 $'myDiv.html'Div content changed';///element.html用于更改html内容 } $“重置”。单击函数{ $'myInput'.val'ABC'; $'myDiv'.html'这里是div内容'; } }; 这里是div内容 名字: 更改内容
重置内容在Jquery中使用HTML值:

//tags who uses value attributes
var jqVar = $('#HTML-tag-id').val();
//other HTML tags
var jqVar = $("#HTML-tag-id").html();
在HTML中设置jquery值:

var jqVar = $('#HTML-tag-id').val();

//putting jqVar value to some other textbox 
$('#HTML-tag-id2').val(jqVar);
//using it in other HTML tag
$('#HTML-tag-id2').html(jqVar);

尝试创建元素和$parent.append或$element.htmlhtml?在我的例子中,我有一个$qty\u rec+thenum.valqty;假设我想获取数量,您如何将其传递给此$'content'。htmlYour HTML here;?我有点confuse@jdoe执行此操作$qty\u rec.htmlqty@jdoe确保数量不为空。您将在console.log中看不到任何内容。你会看到html本身的变化。你的意思是这样吗?变量it=$qty\U rec+最小值valqty;console.logit;$'qtyrcd'.html=it;如果它有数据,请使用$'qtyrcd'.htmit;这是我在console.log inputqty\u rec0.input\u md.radious\u all.innershadow.width\u control\u 95.margin\u control\u 0.qty\u rcvd property value=2属性值=同时变量it=$qty\u rec+thenum.valqty;不正确,因为您希望获取$qty_rec+thenum的值,并且应该使用var it=$qty_rec+thenum.val;从var it使用=$qty\U rec+thenum.val;它应该记录输入的值
var jqVar = $('#HTML-tag-id').val();

//putting jqVar value to some other textbox 
$('#HTML-tag-id2').val(jqVar);
//using it in other HTML tag
$('#HTML-tag-id2').html(jqVar);