简体   繁体   English

在xajax上创建新元素

[英]create new element on xajax

hi everyone it's my again. 大家好,这又是我的。 maybe its a stupid question but i can do it :> 也许这是一个愚蠢的问题,但我可以做到:>

I need to create a div object inside my xajax function. 我需要在xajax函数中创建一个div对象。 I do so 我这样做

$response->create("parent id","The name of the new element","new id");

So far SO good. 到现在为止还挺好。 Next, i assign a property to my new object like this 接下来,我像这样将属性分配给新对象

$response->assign("new id","style.display","block")

again so far so good. 到目前为止,一切都很好。 My problem is when wanting to create a attribute. 我的问题是要创建属性时。 This is my code 这是我的代码

$response->assign("new id","class","name of my class");

in html is something like <div id="p-new id" class="name of my class"> 在html中类似于<div id="p-new id" class="name of my class">

but i can't do this. 但是我做不到。 Any suggestions are very good 任何建议都很好

Thanks. 谢谢。

Remember that ->assign(*id*, *prop*, *value*) is translated into document.getElementById(*id*).*prop* = *value*; 记住->assign(*id*, *prop*, *value*)被翻译成document.getElementById(*id*).*prop* = *value*;

Because class is a reserved word in Javascript, the class attribute is handled by the property className . 因为class是Javascript中的保留字,所以class属性由属性className处理。

So $response->assign("new id","className","name of my class"); 所以$response->assign("new id","className","name of my class"); will work. 将工作。

Why don't you create whole object in one line like: 为什么不在一行中创建整个对象,例如:

$response->assign("parent-id","innerHTML","<div id='p-new id' class='name of my class'>");

or if you can't change parent-id innerHTML create: firstly new-id div: 或者如果您不能更改parent-id innerHTML create:首先是new-id div:

$response->create("parent-id","The name of the new element","new-id");

and then assign it's innerHTML new div: 然后将其分配为innerHTML新div:

$response->assign("parent-id","innerHTML","<div class='name of my class'></div>");

Unfortunatelly you will get structure 不幸的是,您将获得结构

<div id="p-new id"> <class="name of my class"></div> </div>

not as you want 不是你想要的

<div id="p-new id" class="name of my class"></div>

But you can adjust this idea to your needs and create sth like 但是您可以根据自己的需要调整此想法并创建

<div id="outer-sth"><div id="p-new id" class="name of my class"></div></div>

Which I belive is close enough to what you are asking. 我相信,这与您的要求足够接近。

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

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