简体   繁体   English

复制输入值文本并粘贴/添加到另一个输入值文本?

[英]Copy input value text and paste/add to another input value text?

I want to copy this input from page A and paste to page B 我想将此输入从页面A复制并粘贴到页面B

Let say this is Page A : 假设这是A页:

<input type="text" class="Name" id="cName" Value="Hey" readonly/>
    <input type="number" class="Qty" id="cQty" Value="1" readonly/>
        <input type="text" class="Price" id="cPrice" Value="10" readonly/><button class="" id="copy">Copy/?Add to Page B?</button>

This is Page B: 这是B页:

<ol><button class="" id="add">Add</button>
                    <li>
            <input type="text" class="Name" id="pName" Value="" readonly/>
    <input type="number" class="Qty" id="pQty" Value="" />
                <input type="text" class="Price" id="pPrice" Value="" readonly/><button class="" id="cancel">Cancel</button>
                </li><input type="text" class="Name" id="" Value="" readonly/>
    <input type="number" class="Qty" id="tQty" Value="Total Quantity" readonly/>
                <input type="text" class="Price" id="tPrice" Value="Total Price" readonly/></ol>

I read that I can't copy and paste, so is there another way of it? 我读到我无法复制和粘贴,所以还有另一种方法吗? like adding Page A input text straight to Page B input text, like "add to shopping carts?" 例如直接将A页输入文本添加到B页输入文本,例如“添加到购物车?”

Thanks for all the expert here. 感谢所有专家在这里。

If you have no option to use server-side programming, such as PHP, you could use the query string, or GET parameters. 如果没有使用服务器端编程(例如PHP)的选项,则可以使用查询字符串或GET参数。

In the form, add a method="GET " attribute: 在表单中,添加method="GET ”属性:

<form action="b.html" method="GET">
    <input type="text" name="serialNumber" />
    <input type="submit" value="Submit" />
</form>

When they submit this form, the user will be directed to an address which includes the serialNumber (for example) value as a parameter. 当他们提交此表格时,将把用户定向到一个地址,该地址包括serialNumber(例如)值作为参数。 Something like: 就像是:

http://www.example.com/display.html?serialNumber=XYZ

You should then be able to parse the query string - which will contain the serialNumber parameter value - from JavaScript, using the window.location.search value: 然后,您应该能够使用window.location.search值从JavaScript解析查询字符串(其中将包含serialNumber参数值):

// from b.html
document.getElementById("write").innerHTML = window.location.search; // you will have to parse
                                                                     // the query string to extract the
                                                                     // parameter you need

See also JavaScript query string. 另请参见JavaScript查询字符串。

The alternative is to store the values in cookies when the form is submit and read them out of the cookies again once the b.html page loads. 另一种方法是在提交表单时将值存储在cookie中,并在b.html页面加载后再次从cookie中读取它们。

See also How to use JavaScript to fill a form on another page . 另请参见如何使用JavaScript填写另一页上的表单

You can take this value either by form post method or use browser cookies and very easy to implement. 您可以通过表单发布方法或使用浏览器cookie来获取此值,并且非常易于实现。

And the methods varies as per your programming language. 根据您的编程语言,方法也有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM