[英]How can i do jQuery like coding in C language?
How to do jQuery like calls in C language? 如何用C语言调用jQuery?
Say we have a packets (html for example): 假设我们有一个数据包(例如html):
<div id="mymute">
<div>
</div>
<div>
<img src="/agents/sleeping.png" />
</div>
<div>
</div>
</div>
Javascript/Jquery it query that packets and find the image tag and update the src attribute. Javascript / Jquery它查询数据包并找到图像标记并更新src属性。 using simply like this:
像这样使用:
$('#mymute').find('div').find('img').attr('src','/agents/wakeUP.png');
But in C how can i do something like this? 但是在C中我该怎么做呢? (not how to parse a string but how to implement such function().function().function().function().endless...().endless()?
(不是如何解析字符串但是如何实现这样的函数()。function()。function()。function()。endless ...()。endless()?
main.c: main.c中:
int
main () {
"This is a html string".cWayFind("is").cWayFind("etc etc").cWayModify(properties, tonewProperties);
return 0;
}
You probably want to use C++. 您可能想要使用C ++。 There, it's very easy to return an object from a function which can reference the same underlying data.
在那里,从一个可以引用相同底层数据的函数返回一个对象非常容易。 Ie if you have something like
即如果你有类似的东西
struct DOMNode {
DOMNode Find (const char* name);
};
you can immediately type DOMNode ().Find("foo").Find("bar");
你可以立即输入
DOMNode ().Find("foo").Find("bar");
, no special magic required. ,不需要特别的魔法。
If you want to modify the object itself, just return a reference to this
. 如果要修改对象本身,只需返回
this
的引用。
struct DOMNode {
DOMNode& SetAttribute (const char* name, const char* value) { /* ... */; return *this; }
};
Here's a great place to start: 这是一个很好的起点:
http://en.wikipedia.org/wiki/Method_chaining http://en.wikipedia.org/wiki/Method_chaining
You need a jQuery type parser implemented in C++. 您需要一个用C ++实现的jQuery类型解析器。 At this point I do not know of any that exists.
在这一点上,我不知道存在任何存在。
To do something like this usually you pass the receiver, ie this
, as the first argument to each function call. 要做这样的事情通常你传递接收器,即
this
,作为每个函数调用的第一个参数。
cWayModify(cWayFind(cWayFind("This is a html string", "is"), "etc etc"), properties, tonewProperties);
The most inner function call is evaluated first. 首先评估最内部的函数调用。 The dot operator for method call is really just syntactic sugar to make the code more readable;
方法调用的点运算符实际上只是语法糖,使代码更具可读性; The first action that is evaluated occurs first in a chained line of code.
评估的第一个操作首先出现在一个链式代码行中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.