首页 \ 问答 \ 使用jQuery和链接操作DOM元素(Manipulating DOM elements with jQuery and chaining)

使用jQuery和链接操作DOM元素(Manipulating DOM elements with jQuery and chaining)

玩jQuery有点(对不起,完全noob)我想知道为什么这不起作用。 也许我没有获得链接,上下文和DOM操作的方式,但我只是好奇。 这里是:

$("#myDiv")
    .append("h3")
    .append("a")
    .attr("href", "http://example.com")
    .text("Click here")
    .end();

我希望发生的事情是:

  • 选择#myDiv
  • 在里面插入一个H3
  • 然后在H3里面插入一个A标签
  • 将A标签的HREF属性设置为一个URL
  • 然后将A标签的文本设置为“Click Here”

相反,我的页面的标记似乎完全搞砸了,虽然我看不到动态DOM,所以我不知道发生了什么。 我读的jQuery文档错了吗?


Playing around with jQuery a bit (sorry, complete noob) I was wondering why this does not work. Maybe I'm not getting the way chaining, context and DOM manipulation works, but I'm just curious. Here it goes:

$("#myDiv")
    .append("h3")
    .append("a")
    .attr("href", "http://example.com")
    .text("Click here")
    .end();

What I would expect to happen:

  • Select #myDiv
  • Insert an H3 inside it
  • Then inside the H3, insert an A tag
  • Set the A tag's HREF attribute to a URL
  • And then set the A tag's text to "Click Here"

Instead my page's markup seems to get completely screwed up, although I can't see the dynamic DOM so I'm not sure what's happening. Am I reading the jQuery documentation wrong?


原文:https://stackoverflow.com/questions/6298048
更新时间:2022-11-19 06:11

最满意答案

请尝试以下方法:

如果你的响应是在json中,那么以下面的方式使用你的代码,然后在doInBackground(Void... params)使用你的'response' doInBackground(Void... params)

DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(serviceURL);                                   
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();

回复错误你得到的结果..


Try the following :

Use your code in the following manner if your response is in json and then use your 'response' from entity in doInBackground(Void... params):

DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(serviceURL);                                   
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();

Reply with error what you result you get..

相关问答

更多
  • 尝试这个: url = "http://10.0.218.211/post.php"; HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); try { **// Add your data <-** List nameValuePairs = new ArrayList(2); ...
  • 您可以按如下方式打印所有请求详情: HttpPost post = new HttpPost(); post.getAllHeaders(); post.getMethod(); // Post or get request post.getParams(); // Returns params post.getURI(); // Current Uri called 一旦得到回复, response.getAllHeaders(); httpRe ...
  • 您可以创建StringEntity ,将其设置为HttpPost对象,并设置正确的Content-Type : StringEntity entity = new StringEntity("data=" + java.net.URLEncoder.encode(body, "utf-8")); entity.setContentType("application/x-www-form-urlencoded"); httpPost.setEntity(entity); 然后像往常一样发送你的POST请求。 ...
  • 那么HTTP请求有所不同。 在第一个示例中,您使用给定的URL和空体发送HTTP请求。 第二,发送带有较短URL但带有参数的body的HTTP请求。 如果服务器上存在不同的行为,则取决于服务器(或它使用的框架)如何处理此类请求。 如果您想在HTTP级别上看到差异,请使用一些工具来检查输入和输出数据包(请求),例如Wireshark。 Well there is a difference in the HTTP request. In first example, you send HTTP request ...
  • 请尝试以下方法: 如果你的响应是在json中,那么以下面的方式使用你的代码,然后在doInBackground(Void... params)使用你的'response' doInBackground(Void... params) : DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(serviceURL); request ...
  • 尝试在TempData中设置值并在验证操作中访问它并将其传递给验证视图,现在您可以在验证视图中访问故障Ticket模型。 TempData被持久化以用于后续请求。 RedirectToAction infact向浏览器发出302请求,然后重定向到Verify操作,您将从那里获取TempData的ticket 。 [HttpPost] public ActionResult Create(Ticket ticket) { TempData["ticket"] = ticket; return ...
  • 如评论中所述,帖子正文应编码为UTF_8。 As posted in the comments, the post body should have been encoded as UTF_8.
  • 这个检查 if( response.getEntity().getContentLength() > 0) 是不正确的。 http header ContentLength可以设置为0. rfc不强制指定正确的大小。 您应该检查http请求的响应代码。 检查应该是: if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) 然后尝试阅读回复的内容。 通过rfc HTTP 200 request ok , HTTP 204为Req ...
  • 边界是划分消息的各个部分。 除了图像或其他二进制数据之外,我还用它来返回一些XML。 我正在进行视觉分析,并且除了车辆图像之外还会返回跟踪记录(xml或json)。 我也用它来传输相机校准。 校准结构的各个部分作为xml / json / etc在一个区域中发送,而在另一个区域中是将每个像素映射到其真实世界位置(纬度,长度,高度)的二进制表。 没有边界,它假定整个响应是同构的(或用户解析)。 你提供了一个例子。 根据您设置的服务器/客户端,可以使用POST将其设置为服务器,也可以使用GET从服务器返回。 T ...
  • 我找到了解决方案。 将拦截器添加到客户端,我可以在执行之前获得包含所有头的完整请求,因此我不需要处理实体添加头的特殊情况。 HttpClientBuilder builder = HttpClientBuilder.create(); builder = builder.disableContentCompression().disableConnectionState(); builder.addInterceptorLast((HttpRequestInterceptor) (request, con ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的