是否有可能强制重新评估/重新解析HTML? [英] Is it possible to force re-avaluating/re-parsing of HTML?

查看:61
本文介绍了是否有可能强制重新评估/重新解析HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




尝试使用代码时遇到以下问题

将虚拟键盘附加到任何用户的表单:


用户单击一个按钮,我的JavaScript更改outerHTML

of say< textarea - 添加类似ONCLICK =''saveCaret(this)''

等,它还会尝试在按下按钮之前保存用户无法输入的任何文字




a)价值 - (已输入的文本)未分配回来

b)outerHTML仍然相同 - 都在alert()文本和

Hi,

Ran into the following problem while trying to have a code to
attach a Virtual Keyboard to any user''s form:

User clicks a button and my JavaScript changes outerHTML
of say <textarea - adding things like ONCLICK=''saveCaret(this)''
etc. and it also tries to save any text that user could''ve entered
before the button press.

a) Value - (already typed text) is not assigned back
b) outerHTML is still the same - both in alert() text and via


javascript < b> 的点:x = document.body.innerHTML.replace(/< /克, '' &安培; LT; '')代替(/ \\\
/克, '' <峰; br> '' ); document.body.innerHTML = x;
javascript:x=document.body.innerHTML.replace(/</g,''&lt;'').replace(/\n/g,''<br>''); document.body.innerHTML = x;



代码很简单所以我想我们是否有办法强制HTML

通过a重新评估/重新解析按钮点击


(如果我通过< script ....< / scriptline放在按钮上方

那样做一切都没关系 - 因为HTML正在被更改_before_

页面加载结束了)


=================== ====================

function vkb_addAttributes(obj)

{


var obj_value ="" ;; if(obj.value!="")obj_value = obj.value;

var kA =" onFocus =''vkb_txtControl = this;''OnSelect =''vkb_saveCaret(this)''" ;;


var obj_HTML = obj.outerHTML;

var pos = obj_HTML.indexOf(''>'');

var part1 = obj_HTML.substring(0,pos);

var part2 = obj_HTML.substring( pos);

obj.outerHTML = part1 + kA + part2;


obj.value = obj_value;

}

============================================ =


谢谢,

Paul

The code is simple so I wander whether we have a way to force HTML to be
re-avaluated/re-parsed via a button click

(if I do the same via <script....</scriptline placed above the button
then everything is OK - because HTML is being changed _before_ the
page load is over)

=======================================
function vkb_addAttributes(obj)
{

var obj_value = ""; if (obj.value != "") obj_value = obj.value;
var kA=" onFocus=''vkb_txtControl=this;'' OnSelect=''vkb_saveCaret(this)''";

var obj_HTML = obj.outerHTML;
var pos = obj_HTML.indexOf(''>'');
var part1 = obj_HTML.substring(0,pos);
var part2 = obj_HTML.substring(pos);
obj.outerHTML = part1 + kA + part2;

obj.value = obj_value;
}
=============================================

Thanks,
Paul

推荐答案



Paul Gorodyansky写道:

Paul Gorodyansky wrote:

用户点击一个按钮,我的JavaScript更改outerHTML

of say< textarea - 添加像ONCLICK这样的东西=''saveCaret(this)''

等等,它还会尝试在按下按钮之前保存用户无法输入的任何文本


User clicks a button and my JavaScript changes outerHTML
of say <textarea - adding things like ONCLICK=''saveCaret(this)''
etc. and it also tries to save any text that user could''ve entered
before the button press.



为什么要添加元素onclick以响应用户点击?

是否用户有很多选择,每个选择为元素的onclick分配一个

不同的事件?如果没有,那么你应该只需添加元素onclick onload,就像这样:
http://simon.incutio.com/archive/200...6/addLoadEvent


function addLoadEvent(func){

var oldonload = window.onload;

if(typeof window.onload!=''function''){

window.onload = func;

} else {

window.onload = function(){

if(oldonload){

oldonload();

}

func();

}

}

}


addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);

addLoadEvent(function(){

/ *更多代码在页面加载时运行* /

});

Why are you adding to the elements onclick in reaction to a user click?
Is it that the user has many choices, and each choice assigns a
different event to the element''s onclick? If not, then you should just
add to the elements onclick onload, with something like this:
http://simon.incutio.com/archive/200...6/addLoadEvent

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ''function'') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
/* more code to run on page load */
});





Jake Barnes写道:
Hi,

Jake Barnes wrote:

>

Paul Gorodyansky写道:
>
Paul Gorodyansky wrote:

用户单击按钮,我的JavaScript更改outerHTML

of say< textarea - 添加类似ONCLICK =''saveCaret(this)''

等,它还会尝试在按下按钮之前保存用户可能已经输入的任何文本


User clicks a button and my JavaScript changes outerHTML
of say <textarea - adding things like ONCLICK=''saveCaret(this)''
etc. and it also tries to save any text that user could''ve entered
before the button press.



为什么要添加元素onclick以响应用户点击?

是否用户有很多选择,每个选择为元素的onclick分配一个

不同的事件?


Why are you adding to the elements onclick in reaction to a user click?
Is it that the user has many choices, and each choice assigns a
different event to the element''s onclick?



不,只是示例onclick。


但我想将它们添加到< textarea NOT页面加载,但是以后 -

当用户点击我的按钮时(因为他/她可能永远不需要

虚拟键盘 - 为什么他们应该更改输入字段HTML?)


请再次看第一条消息,看看我的意思。


-

问候,

Paul

No, just sample onclick.

But I want to add them to <textarea NOT on page load, but later -
when a user clicks on my button (because s/he may never need
Virtual Keyboard - why them should I change input fields HTML?)

Please see 1st message once more to see what I mean.

--
Regards,
Paul




是的,顺便说一下,你需要一些SOAP和AJAX,双关语:),SOAP
$标记中的b $ ba元数据文件,你的HTML片段和AJAX,Asynchronous

Javascript和XML,没关系XML部分,它确实管理了任何ASCII,但最初打算对于XML,虽然它也将XML

元数据作为节点。异步意味着,你不会在页面加载上提供片段,或者在页面加载时立即提供或预先加载

与页面同步,你是异步进行的,在这种情况下,通过onclick,在事件发生后从服务器加载元数据字符串html

标记。许多人使用的是

原型。 set,这是一个预先生成的文件,用于向Web服务器异步请求文件
。只需谷歌吧。


Danny

Yes, by the way, you need some SOAP and AJAX, pun intended :), SOAP
a metadata file in markup, your HTML fragment, and AJAX, Asynchronous
Javascript And XML, nevermind the XML part, it really manages
anything ASCII, but originally intended for XML, though it does XML
metadata as nodes as well. The Asynchronous means, you don''t serve
the fragment(s) on pageload, or at once upon pageload or preloaded
synchronously with the page, you do it asynchronously, at a later
time, in this case, by onclick, to load the metadata string in html
markup from the server upon the event. One used by many is the
"Prototype" set, which is a premade one for requesting files
asynchronously to the webserver. Just google for it.


Danny


这篇关于是否有可能强制重新评估/重新解析HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆