- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我为什么要使用或需要使用具有隐藏属性的额外输入元素来制作一个在内部搜索给定网站的网站搜索框。
<div id="search_box">
<form name="searchform" action="http://www.google.com/search" method="get" target="_blank">
<input name="sitesearch" type="hidden" value="www.example.com" />
<input name="as_q" onfocus="this.value=''" type="text" size="20" value="Search www.example.com" title="Enter your search here" />
<input title="Begin Search" type="submit" value="Search" />
</form>
</div>
此外,我是否真的需要使用 Javascript onfocus="this.value=''"
在用户点击后清除“Search www.example.com”的文本/值.为什么这不起作用,我怀疑是因为人们不能通过“定位”某些“属性”。 CSS 并且没有针对给定 HTML 属性的“替代”CSS 属性。
input[type="text"]:focus
{
value: "";
}
以上将失败,因为我不能(或者我可以?)定位 value 属性!但是,将 Javascript 用于像这样的非常小的功能似乎有点矫枉过正。几乎就像使用 JS 实现悬停效果而不是 CSS pseudo:hover。
最佳答案
Why am I using, or need to use the extra input element with the attribute of hidden to make a web site search box that searches the given web site internally.
您必须以某种方式告诉搜索引擎您要将搜索限制在特定站点。通常这是通过一个隐藏的输入字段完成的,因为它在提交表单时包含但不显示给用户。
但是它不需要是隐藏元素。您也可以将其放在 text
、radiobutton
、checkbox
或 select
中。唯一的要求是它被发送到名称为“sitesearch”的搜索引擎,并带有您选择的网站的值。
do I really need to use Javascript onfocus="this.value=''" to clear the text/value of "Search www.example.com" once the user has clicked on it.
您可以从一开始就设置 value=''
并使用新的 html5 属性 placeholder='Search www.example.com'
。或者在页面的某处使用描述性文本。
But it just seems an overkill to use Javascript for a very small functionality like this one. Almost like using JS for hover effects rather than CSS pseudo:hover.
您可能认为这是矫枉过正,但多年来这是唯一的方法。早在 CSS 实现之前,JavaScript 就已经出现在浏览器中。悬停效果必须在 javascript 中实现,因为 :hover
直到 CSS2 才被引入。您要在本例中使用的占位符效果最近才通过 HTML5 实现。
关于javascript - 为什么要使用额外的输入元素来创建内部网站搜索框(和),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12238436/
我想为我们的网站创建一个自定义搜索框。让它工作如下: function bookssearch(bs) { window.open('http://webpac.kdu.edu.my/s
我需要向我的搜索系统添加一个弹出窗口事件 - 当客户仅输入 2 个字符时,它应该弹出一个带有警报 e 的小表格。 G。 “搜索时必须输入至少 3 个字符...”并且背景应变灰。 这对我来说可能吗?这是
我的以下功能存在格式问题。正如您将在下面看到的,它大部分都有效,只是搜索框的格式不是我想要的(我想复制 typeahead Twitter Bootstrap 功能): 用户可以在搜索框中输入书名,在
我正在尝试使用 php 和 jquery 实现一个搜索框(搜索结果来自数据库)。我想要做的是,当用户在搜索框中键入内容时,将进行查询以查找包含用户在搜索框中输入的关键字的数据。我遇到的问题是我有这样的
我想知道为什么当我在我的计算机上本地加载 Angular 搜索框时它不起作用。我使用的是相同的代码,当我使用 codepen、plunker 或 jsfiddle 等网站时,它确实有效。它无法正常工作
我想知道如何在鼠标悬停事件上将焦点设置到输入字段。 我想知道当鼠标悬停在输入字段或焦点字段上时如何加载输入字段或焦点字段,以便在光标触摸或鼠标悬停在搜索框的输入字段上时轻松准备打字。 最佳答案 您可以
我有index.jsp,我想搜索视频,但每当我搜索时,它都会给我带来不同的错误,并且我无法获得结果,就像它应该将用户带到搜索文本所在的页面一样。 Search.java import java.io.
所以搜索就像'Ozzie Smith' 第一个表有 (username, fname, lname) = osmith, ozzie, smith 第二张表有 (username, team) = o
有什么方法可以启动/打开带有代码的搜索框,或者只需单击搜索键即可? 最佳答案 SearchManager mgr = ((SearchManager) getSystemService(Context
废话不多说了,直接给大家贴关键代码了,具体代码如下所示: ? 1
我想制作一个具有自动建议并搜索 XML 文件中特定标签的搜索框。我怎样才能实现这一点? 最佳答案 这取决于您所说的 XML 文件的含义。 XML 文件在某些服务器上可用吗? 看看jQuery及其
我用javaee6和jsf2开发了一个小应用程序。我想要一个没有按钮的搜索字段(只需键入并按 Enter 键并给出结果)。我在 bean 中有一个搜索方法: public Book searchByT
首先,这个标题是我能想到的最好的标题。 我编写了一个非常短的小脚本来执行实时搜索。 它的基本原理是: (function ($) { $.fn.SearchThing = function (
我正在用 Java 创建一个简单的桌面应用程序,它显示当前正在运行的服务。我想在顶部添加一个谷歌搜索栏,可以直接在默认浏览器中打开应用中输入的关键字的谷歌搜索结果(网页)。 最佳答案 您应该从输入框中
美好的一天。我正在研究我的搜索框。我如何从多列中进行搜索。除了“id”列之外,我还有名字、姓氏、RFIDnum。我如何将它们添加到我当前的代码中。 这是我的代码: DataView dv = new
在 this site ,右上角的搜索框不起作用。 我尝试向父元素添加 z-index: .col-right-one-thirds { max-width: 22.38033333em;
我想要在 bootstrap 3+ 中带有选择选项和清除按钮的大搜索框。我尝试了下面的代码,但它没有正确对齐。
执行此代码$("input[name=q]").value = "Hello"; 应在 stackoverflow 搜索框中输入“Hello”。然而它仍然是空的。为什么? 最佳答案 因为它应该是: $
我是新手。我尝试制作一个搜索框。当我在 Firefox 上打开它时。对我来说没关系。然后我在 IE、Chrome 和 Safari 中执行此操作。实际上并不酷。有谁知道我的问题,请帮我解决一下? 我想
当用户加载我的页面时,浏览器中第一个激活的元素是我的菜单按钮之一。 我的页面上有一个搜索框(表单域),我希望它成为第一个激活的东西。 我所说的“事件”是指当用户按下选项卡按钮时,它会循环浏览网站上的所
我是一名优秀的程序员,十分优秀!