简体   繁体   English

我怎样才能用C语言编写jQuery?

[英]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.

相关问题 我该如何在jQuery中执行类似此照片库的操作? - How can I do something like this photo gallery in jQuery? 如何在jquery mobile中更改语言? - How do I change the language in jquery mobile? 我如何在jQuery之类的函数内部执行变量对象? - How can I do variable object inside of function like jQuery do? 在我的 HTML 中没有任何硬编码的情况下,我能做些什么来修复我的 jQuery? - what can I do to fix my jQuery without any hard-coding in my HTML? 如何构建 jQuery 之类的事件? - How can I build jQuery like events? 我们可以像C#一样在jQuery中进行文件处理吗? - Can we do file handing in jQuery like C#? 如何指定 CKEditor(jquery 版本)的界面语言? - How do I specify the interface language for CKEditor (jquery version)? 我怎样才能像css-transitions一样使jquery toggleClass动画化适当的类的孩子? - how can i make jquery toggleClass animate children to appropriate classes just like css-transitions do? 如何得到 <div> 用JQuery显示和滚动点击以水平滚动编码? - How do I get <div> to show & scroll with JQuery click to horizontally scroll coding? 如何使用 jquery 将数据表的内容语言更改为法语? - How can I change the content language of the datatables to French with jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM