简体   繁体   English

使用bookmarklet更改文本框大小

[英]Change the text box size using bookmarklet

Form text area resizer is a bookmarklet that will allow the user to change the size of textarea. 表单文本区域大小调整器是一个书签,可让用户更改文本区域的大小。 Eg 例如

javascript: (function() {
    var i, x;
    for (i = 0; x = document.getElementsByTagName("textarea")[i]; ++i) x.rows += 5;
})()

But I am looking for a bookmarklet that will allow me to change the size of text box. 但是我正在寻找一个允许我更改文本框大小的书签。 Eg on the following page I will like to increase the size of name and email input boxes. 例如, 在下一页上,我想增加名称和电子邮件输入框的大小。

From what I know there is no way to do this. 据我所知,没有办法做到这一点。 One could use CSS resize:both; overflow: auto; 一个可以使用CSS resize:both; overflow: auto; resize:both; overflow: auto; , but this does not seem to work in various browsers. ,但这似乎不适用于各种浏览器。 (Perhaps I'm doing something wrong ). (也许我做错了 )。

One way could be to replace all input fields with a dirty copy, but this seems to be a candidate for breaking existing scripts (native to the page etc.). 一种方法是用脏副本替换所有输入字段,但这似乎是破坏现有脚本(本机页面等)的一种选择。 As an example the element is no longer going to be of type "text" and if native script rely on this, it gets broken. 例如,该元素将不再是“文本”类型,并且如果本机脚本依赖于此,则该元素将损坏。 Event listeners would be broken, etc. 事件监听器将被破坏,等等。

Anyhow, if one still want to, a quick first draft could perhaps be something like this : 无论如何,如果仍然愿意,快速的初稿可能是这样的

(function() {
    var x, n, i = 0,
        t = document.createElement('TEXTAREA');
    t.rows = 3;
    while ((x = document.getElementsByTagName('INPUT')[i])) {
        if (x.type === "text") {
            n = x.parentNode.insertBefore(t.cloneNode(), x);
            x.parentNode.removeChild(x); 
            n.id = x.id;   
            n.name = x.name;
            n.innerText = x.value;
        } else { 
            ++i;   
        }
    }
})();

Or as bookmarklet: 或作为书签:

javascript:(function(){var x,n,i=0,t=document.createElement("TEXTAREA");t.rows=3;while((x=document.getElementsByTagName("INPUT")[i]))if(x.type==="text"){n=x.parentNode.insertBefore(t.cloneNode(),x);x.parentNode.removeChild(x);n.id=x.id;n.name=x.name;n.innerText=x.value}else++i})();

这以我想要的方式更改了输入字段:

javascript:(function(){var%20i,x;%20for(i=0;x=document.getElementsByTagName("INPUT")[i];++i)%20x.size%20+=%2035;%20})()

I think the way you are approaching it is not the best way. 我认为您采用的方式并不是最好的方式。 Your bookmarklet function should call some external JavaScript and you should place all your logic in that script. 您的bookmarklet函数应调用一些外部JavaScript,并将所有逻辑放入该脚本中。 In that case debugging the script should be easier for you. 在这种情况下,调试脚本对您来说应该更容易。

Consider this Sample Code: 考虑以下示例代码:

<a href="javascript:(function(){  script=document.createElement('SCRIPT');script.src='http://path/to/your/JS';document.body.appendChild(script);})()"> This is a sample bookmarklet </a>

So now the global JS file you are including should contain your JS and all the logic. 因此,现在包含的全局JS文件应包含JS和所有逻辑。 Once you have done it do the above steps with the plugin. 完成后,请使用插件执行上述步骤。 This time insert break points at desired locations to debug your code. 这次在所需位置插入断点以调试代码。

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

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