我有一个简单的 html 文件上传表单,它是这样的:
<form action="upload_file.php" id="theForm" method="post" onsubmit="return validateForm()" enctype="multipart/form-data">
<label for="file">Files:</label>
<input type="file" name="file[]" id="file1"><button id="rem1" type="button">Remove File</button>
...
...
<input type="file" name="file[]" id="file99"><button id="rem99" type="button">Remove File</button>
<input type="submit" name="submit" value="Submit">
</form>
Run Code Online (Sandbox Code Playgroud)
输入是动态创建的。我需要知道被点击的按钮的 id。
作为一名初级程序员,我在这个网站上找到了很多有用的信息,但找不到我的具体问题的答案。我想从网页中抓取数据,但是我有兴趣抓取的一些数据只能在单击“更多”按钮后才能获得。下面的代码执行时不会产生错误,但它似乎没有单击“更多”按钮并在页面上显示附加数据。我只对查看“成绩单”选项卡上的信息感兴趣,这对我来说似乎有点复杂,因为其他选项卡上有“更多”按钮。我的代码的相关部分如下:
from mechanize import Browser
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains
import urllib2
import mechanize
import logging
import time
import httplib
import os
import selenium
url="http://seekingalpha.com/symbol/IBM/transcripts"
ua='Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 (compatible;)'
br=Browser()
br.addheaders=[('User-Agent', ua), ('Accept', '*/*')]
br.set_debug_http(True)
br.set_debug_responses(True)
logging.getLogger('mechanize').setLevel(logging.DEBUG)
br.set_handle_robots(False)
chromedriver="~/chromedriver"
os.environ["webdriver.chrome.driver"]=chromedriver
driver=webdriver.Chrome(chromedriver)
time.sleep(1)
httplib.HTTPConnection._http_vsn=10
httplib.HTTPConnection._http_vsn_str='HTTP/1.0'
page=br.open(url)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(5)
actions=ActionChains(driver)
elem=driver.find_element_by_css_selector("div #transcripts_show_more div#more.older_archives")
actions.move_to_element(elem).click()
Run Code Online (Sandbox Code Playgroud) 我已将点击处理程序附加到表格行元素,我需要一些帮助来从点击处理程序中排除带有类子菜单的元素。
我尝试使用 jQuery :not选择器成功排除整个td元素,但这不是我想要的。
下面的代码需要jQuery、Bootstrap和FontAwesome才能工作。请参考上面的 JsFiddle 链接。
HTML
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Details</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td>Name 1
<div class="pull-right sub-menu">
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="#">Edit</a></li>
<li><a href="#">Delete</a></li>
<li><a href="#">Block</a></li>
</ul>
</div>
</div>
</td>
<td>New User</td>
<td>Pending</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
Javascript
$(function() {
$('table tr').on('click', function() {
alert('Clicked');
}); …Run Code Online (Sandbox Code Playgroud) 使用 JQuery,我需要编写一个函数,在单击两个按钮(edit0、edit1)中的任何一个时调用。我有以下代码:
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$('[id^=edit]').click(function() {
alert("1111");
});
</script>
</head>
<body>
<button id="edit0" class="edit"> edit </button>
<button id="edit1" class="edit"> edit </button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,单击按钮时没有任何反应。我尝试将脚本替换为:
$('button[class="edit"]').click(function() {
alert('1111');
});
Run Code Online (Sandbox Code Playgroud)
但结果是一样的。
我真的花了一整天的时间研究 Unity C# Raycasting 的光线,但我没有什么可展示的。我研究了教程、在线资源、堆栈溢出问题,甚至逐字逐句复制了脚本,希望 Unity 最终能够识别我实际使用 Raycast 的所有尝试。这是一个使用 Raycast 的脚本示例,它对我不起作用:
if (mouseDown) {
print ("mouse is down");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
print ("response???");
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得这应该有效......但事实并非如此。mouseDown 正在正常工作,但是当我单击我的对象时,它拒绝确认从我的鼠标位置到对象的射线命中。我还应该提到该项目是二维的。有什么建议?
添加和删除类的最佳方法是什么,来回单击按钮?
$('button.hamburger').on('click', function(){
$(this).addClass('is-active');
});
$('button.is-active').on('click', function(){
$('button.is-active').removeClass('is-active');
});
Run Code Online (Sandbox Code Playgroud)
它不会删除 .is-active 类。
我是否需要 if 语句来检查元素是否为 .hasClass()?
我正在尝试使用 wxpython 检测位图上的 CLI。on_click 过程似乎在没有 CLIC 的情况下运行,并且在单击时不运行。我做错了什么?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import os
import wx
import wx.lib.agw.thumbnailctrl as TC
import Image
filename="Raphael-Poli-angle.png"
class MyForm(wx.Frame):
def on_clic(self):
print "clicked"
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Choose Dot in Picture", size=(700,500))
self.panel = wx.Panel(self, wx.ID_ANY)
png = wx.Image(filename, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
image=wx.StaticBitmap(self.panel, -1, png, (1, 1), (png.GetWidth(), png.GetHeight()))
image.Bind(wx.EVT_LEFT_DOWN, self.on_clic())
self.Show(True)
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
Run Code Online (Sandbox Code Playgroud) 我是 Android 开发的初学者,这是我在stackoverflow上发表的第一篇文章。我想问如何在卡片视图上添加单击事件,以便每当我单击每张卡片时都会打开相应的布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:id="@+id/card_view"
xmlns="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:orientation="vertical"
android:padding="12dp">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:elevation="12dp"
android:src="@drawable/profile"
tools:ignore="ContentDescription,UnusedAttribute" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Arbaz"
android:textSize="20sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Arbaz"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我尝试模仿用户单击用户名字段(例如)时的行为,并且将自动选择所有文本(名称),以便更轻松地用新文本替换它。但是,当用户再次单击该字段时,文本/名称将变为未选中状态,因此用户可以继续从光标写入文本。我确信每个人都知道我想描述什么,因为当我们在文本字段中写入或想要修改其内容时,我们都多次遇到过这种情况......
所以问题是当我使用 Enter focus 事件并应用 SelectAll() 时,根本不起作用!文本仍未选择。我也尝试使用 Click 事件,效果很好,但是第二次单击时遇到了困难,因为所有鼠标单击再次运行 SelectAll() 方法,文本始终仍然处于选中状态。也许我可以使用存储选择状态的全局变量文本和更改状态反之亦然,但如果没有必要,我不想使用任何额外的变量(每个变量都用于所有 TextBox...不)。
应该有一个简单而优雅的解决方案,因为许多应用程序和网站都使用这种行为来使用户的生活更轻松。我阅读了一些论坛并找到了一些解决方案,但它们看起来比我希望的更复杂。
这是我的代码的相关部分......没什么特别的!
private void G_tbx_canvasSize_Enter(object sender, EventArgs e)
{
(sender as TextBox).SelectAll();
}
Run Code Online (Sandbox Code Playgroud)
这应该以这种方式工作:
请帮忙!我不明白为什么会出现这种情况,这不应该发生......
提前致谢!
我希望能够安装一些 python 代码,使用 python-click 和命令,使用setup.py. 我有以下完整代码:
import click
@click.group()
@click.option(
"-v",
"--verbose",
count=True,
default=0,
help="-v for DEBUG",
)
def cli(verbose):
print(verbose)
@cli.command("list")
@click.option(
"--option1"
)
def my_list_command(option1):
print(option1)
@cli.command("find")
@click.option(
"--option2"
)
def my_find_command(option2):
print(option2)
if __name__ == '__main__':
cli()
Run Code Online (Sandbox Code Playgroud)
它定义了两个命令list和find。例如,当我按照mycode.py我的方式保存该文件时
python mycode.py list --option1 opt1
python mycode.py find --option2 opt2
Run Code Online (Sandbox Code Playgroud)
并且代码按预期工作,即我有两个带有选项的命令。
但是,当我现在尝试安装此代码setup.py如下
from setuptools import setup, find_packages
setup(
name='MyCode',
install_requires=[
'click',
],
entry_points={
'console_scripts': [
'mytest=mycode.cli'
],
},
) …Run Code Online (Sandbox Code Playgroud) click ×10
jquery ×3
button ×2
c# ×2
events ×2
javascript ×2
onclick ×2
python ×2
addclass ×1
android ×1
element ×1
html-table ×1
mouse ×1
python-3.x ×1
raycasting ×1
removeclass ×1
setup.py ×1
textbox ×1
view ×1
web-scraping ×1
winforms ×1
wxpython ×1