小编Sco*_*tt 的帖子

Socket.io中的io.on和socket.on之间的区别?

我对使用函数传递的'socket'参数感到困惑(在'enigma'部分中).然后参数使用'socket.on'.io.on和socket.on有什么区别?

以下代码略微改编自Socket.io聊天应用程序示例.

变量

var http = require('http');
var express = require('express');
var app = express();
var server = http.createServer(app)
var io = require('socket.io').listen(server);
Run Code Online (Sandbox Code Playgroud)

io.on('connection', function (socket) {
  console.log('user connected');
  socket.on('message', function(msg) {
    console.log('message: ' + msg);
    io.emit('message', msg);
  })
});
Run Code Online (Sandbox Code Playgroud)

启动服务器

server.listen(3000, function() {
  console.log('server is running');
});
Run Code Online (Sandbox Code Playgroud)

index.jade

body
  script(src="/socket.io/socket.io.js")

form(method='post', action="/")
  input(type='text', id='user', autocomplete='off')
  input(type='submit', onClick="myFunc()")

strong messages:
  p(id="messages")

script.
  var socket = io();

  socket.on('message', function(msg) {
    console.log('client: ' + msg);
  });

  function myFunc() {
    var text …
Run Code Online (Sandbox Code Playgroud)

socket.io

7
推荐指数
1
解决办法
6354
查看次数

无法隐藏Bootstrap中的<br>

出于某种原因,我无法隐藏<br>仅在小屏幕尺寸上显示的标签.它不会出现在小屏幕上.它适用于其他屏幕尺寸.它适用于其他标签.有关<br>屏幕尺寸小的标签的东西.

 <div class="row">
  <img src="static/works_3.jpg" class="img-responsive works-photo col-md-4 col-sm-12"><br class="hidden-xs hidden-md hidden-lg">
  <img src="static/works_3.jpg" class="img-responsive works-photo col-md-4 col-sm-12"><br class="hidden-xs hidden-md hidden-lg">
  <img src="static/works_3.jpg" class="img-responsive works-photo col-md-4 col-sm-12"><br class="hidden-xs hidden-md hidden-lg">
 </div>
Run Code Online (Sandbox Code Playgroud)

html css twitter-bootstrap

4
推荐指数
1
解决办法
8860
查看次数

Flask没有获得复选框值

当我点击提交按钮时,我正在尝试打印Flask中的复选框值.

app.py片段:

@app.route('/test2', methods=['GET', 'POST'])
def test2():

    if request.method == "POST":
        if request.form['submit'] == 'submit':
            print(request.args.get('check'))

    return render_template('test.html')
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="container"><br>
  <form role="form" method="post">
    <input type="checkbox" name="check" value="test">
    <button type="submit" name="submit" value="submit">Submit</button>
  </form>
</div>
Run Code Online (Sandbox Code Playgroud)

点击提交按钮后返回"无".

我也试过request.form.get()

@app.route('/test2', methods=['GET', 'POST'])
def test2():

    if request.method == "POST":
        if request.form['submit'] == 'submit':
            print(request.form.get('check'))

    return render_template('test.html')
Run Code Online (Sandbox Code Playgroud)

这也返回'无'.

python checkbox request flask

3
推荐指数
1
解决办法
9263
查看次数

不能换吗?JavaScript 中的符号?

普朗克

我想用空格替换回车符,以便用户可以键入(?是用户按回车键):

These?

are?

some?

words.
Run Code Online (Sandbox Code Playgroud)

它将转换为:

These are some words.
Run Code Online (Sandbox Code Playgroud)

然后我想使用 .split() 从这些单词中创建一个数组。所以所需的输出应该是:

["These", "are", "some", "words."]
Run Code Online (Sandbox Code Playgroud)

我收到的输出是:

["These?are?some?words."]
Run Code Online (Sandbox Code Playgroud)

javascript regex

2
推荐指数
1
解决办法
2992
查看次数

如何在Jinja循环中传递多个参数?

我有两个清单:

seller = ["Bob", "Joe", "Tim"]
cash = [12, 25, 67]
Run Code Online (Sandbox Code Playgroud)

我在模板中传递了两个参数:

...

return render_template("sales.html", sellers=sellers, seller_cash=seller_cash)
Run Code Online (Sandbox Code Playgroud)

我想在同一个循环中呈现两个参数:

{% for seller in sellers %}
  <p><strong>{{seller}}: {{cash}}</p>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

显然,这不起作用.有没有办法在同一个循环中有两个参数?

python jinja2 flask

1
推荐指数
1
解决办法
1714
查看次数

可以在美丽的汤中按类别搜索吗?

在BeautifulSoup中,您可以使用soup.find_all进行搜索。例如,我使用搜索了一个页面

soup.find_all("tr", "cat-list-row1")
Run Code Online (Sandbox Code Playgroud)

显然,这带来了每个名为cat-list-row1的tr类。我想知道是否有可能在整个页面中搜索名为“ cat-list-row1”的任何类,而不是仅将其限制为元素为“ tr”的类。

python beautifulsoup

0
推荐指数
1
解决办法
2405
查看次数

无法在Flask中使用Jinja传递变量

表单的操作将输入发送到名为soldfor的路由.我试图将变量ID传递给soldfor.当我点击提交按钮时,我收到此错误:

TypeError:soldfor()只取1个参数(给定0)

register_results.html的渲染:

return render_template('register_results.html', results=results, ID=ID)
Run Code Online (Sandbox Code Playgroud)

register_results.html:

<form role="form" method="POST" action="{{ url_for('soldfor', ID={{ ID }}) }}">
      <div class="input-group">
        <input type="number" class="form-control" placeholder="Sold For" autocomplete="off" name="soldfor">
          <span class="input-group-btn">
            <button class="btn btn-default" name="soldfor" value="soldfor" type="submit">Sell!</button>
        </span>
      </div>
  </form>
Run Code Online (Sandbox Code Playgroud)

soldfor路线:

@app.route("/soldfor", methods=["POST"])
def soldfor(ID):

    soldfor = request.form['soldfor']

    print(soldfor)

    g.db = connect_db()

    g.db.execute("UPDATE yardsale SET SF = ? WHERE ID = ?", (soldfor, ID,))

    g.db.commit()
    g.db.close()

    return redirect(url_for('index'))
Run Code Online (Sandbox Code Playgroud)

python jinja2 flask

0
推荐指数
1
解决办法
2706
查看次数